﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MM.Commmon.UI;
using MM.Common.Base;
using System.Reflection;
using System.IO;
using System.Diagnostics;

namespace MMTJ
{
    public partial class FrmAbout : FrmBase
    {
        private List<string> FileList = new List<string>();
        public FrmAbout()
        {
            InitializeComponent();
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            string data = "";
            for (int i = 0; i < this.lbDllFile.Items.Count; i++)
            {
                data = data + this.lbDllFile.Items[i].ToString() + "\r\n";
            }
            Clipboard.SetDataObject(data);
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        protected void DispInfo()
        {
            this.txtInfo.Text = "";
            try
            {
                object[] customAttributes = Assembly.LoadFrom(this.FileList[this.lbDllFile.SelectedIndex].ToString()).GetCustomAttributes(false);
                string version = "";
                string product = "";
                string copyright = "";
                string title = "";
                foreach (object obj2 in customAttributes)
                {
                    if (obj2.GetType().FullName == "System.Reflection.AssemblyFileVersionAttribute")
                    {
                        version = ((AssemblyFileVersionAttribute)obj2).Version;
                    }
                    if (obj2.GetType().FullName == "System.Reflection.AssemblyProductAttribute")
                    {
                        product = ((AssemblyProductAttribute)obj2).Product;
                    }
                    if (obj2.GetType().FullName == "System.Reflection.AssemblyCopyrightAttribute")
                    {
                        copyright = ((AssemblyCopyrightAttribute)obj2).Copyright;
                    }
                    if (obj2.GetType().FullName == "System.Reflection.AssemblyTitleAttribute")
                    {
                        title = ((AssemblyTitleAttribute)obj2).Title;
                    }
                }
                this.txtInfo.Text = "产品标题：" + title + "\r\n产品名称：" + product + "\r\n版 本 号：" + version + "\r\n版权所有：" + copyright;
            }
            catch
            {
            }
        }

        private void FrmAbout_Load(object sender, EventArgs e)
        {
            this.Text = "关于 " + SystemInfo.SystemName;
            this.lblSystemUsername.Text = "使用单位：" + SystemInfo.OrgHeadName;
            this.lblSystemName.Text = SystemInfo.SystemName + "  版本 " + SystemInfo.CopyWrite;
            this.lblServiceTel.Text = this.lblServiceTel.Text + ConfigFunction.GetSystemConfig("Telephone", "88888888", "服务电话", "C");
            this.lblServiceEmail.Text = this.lblServiceEmail.Text + ConfigFunction.GetSystemConfig("EMail", "@", "服务EMail", "C");
            this.lbDllFile.Items.Clear();
            foreach (string str in Directory.GetFiles(Application.StartupPath))
            {
                if ((str.IndexOf(".exe") == (str.Length - 4)) || (str.IndexOf(".dll") == (str.Length - 4)))
                {
                    int num = str.LastIndexOf(@"\");
                    if (str.Substring(num + 1).IndexOf("MM.") == 0)
                    {
                        string item = str.Substring(str.LastIndexOf('\\') + 1, (str.Length - str.LastIndexOf('\\')) - 1).PadRight(0x2d, ' ') + " " + File.GetLastWriteTime(str).ToString("yyyy-MM-dd hh:mm:ss");
                        this.lbDllFile.Items.Add(item);
                        this.FileList.Add(str);
                    }
                }
            }
            if (this.lbDllFile.Items.Count > 0)
            {
                this.lbDllFile.SelectedIndex = 0;
                this.DispInfo();
            }
        }


        private void lbDllFile_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.DispInfo();
        }

        private void llblLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start("http://www.baidu.com");
        }
    }
}
